<template>
    <div style="min-width:1042px">
       <div v-if="$route.path == '/personalAdmin/newLeave'">
            <div class="vs-search-box" style="padding: 24px 22px 0 0px;">
                <el-form ref="form" :inline="true" :model="paging" label-width="90px">
                    <el-form-item label="门店">
                        <el-input style="width:240px" v-model="paging.store"></el-input>
                    </el-form-item>
                    <el-form-item label="提交时间">
                        <el-date-picker
                        style="width:240px"
                        v-model="paging.submit_time"
                        value-format="yyyy-MM-dd"
                        type="date"
                        placeholder="选择日期">
                        </el-date-picker>
                    </el-form-item>
                    <el-form-item label="" class="fl-right">
                        <el-button @click="init" >重置</el-button>
                        <el-button @click="handleCurrentChange(1)" type="primary">查询</el-button>
                    </el-form-item>
                    <el-form-item label="申请人">
                        <el-input style="width:240px" v-model="paging.name"></el-input>
                    </el-form-item>
                    <el-form-item label="请假类型">
                        <el-select v-model="paging.type" style="width:240px" placeholder="请选择">
                            <el-option
                                v-for="(item,i) in ['事假','病假','产假','婚嫁','陪产假','其他','年假','调休假']"
                                :key="i"
                                :label="item"
                                :value="i+1">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-form>
            </div>
            <div class="vs-table-box">
                <div class="operation-box">
                    <!-- <el-button class="left-auto" @click="derive" :loading="isDerive" icon="el-icon-upload2" size="medium" >导出</el-button> -->
                    <el-button
                        class="btn-upload left-auto"
                        :loading="isDerive"
                        size="medium"
                        icon="el-icon-upload2"
                        plain
                    >
                        <input ref="uploadPai" @change="leaveImport" type="file" name="" id="" /> 导入 </el-button>
                    </div>
                <el-table 
                :header-cell-style="{background:'#f5f6f8'}" 
                v-loading="loading" 
                :data="monthList" 
                header-row-class-name="has-gutter-table" 
                style="width: 100%">
                    <el-table-column prop="number" label="审批编号" ></el-table-column>
                    <el-table-column prop="submit_time" label="提交时间" width="150" > </el-table-column>
                    <el-table-column prop="name" label="申请人" ></el-table-column>
                    <el-table-column prop="store" label="门店"></el-table-column>
                    <el-table-column prop="position.title" label="请假类型">
                        <template slot-scope="scope">
                            {{scope.row.type | leaveType}}
                        </template>
                    </el-table-column>
                    <el-table-column prop="nationality" label="请假时间" width="170">
                        <template slot-scope="scope">
                            {{scope.row.start_time}} ~ {{scope.row.end_time}}
                        </template>
                    </el-table-column>
                    <el-table-column prop="duration" label="请假时长"></el-table-column>
                    <el-table-column prop="status_text" label="审批状态"></el-table-column>
                    <el-table-column label="操作">
                        <template slot-scope="scope">
                            <span @click="leaveDel(scope.row)" class="tab-red-text">删除</span>
                        </template>
                    </el-table-column>
                </el-table>
                <div class="vs-paging-box">
                    <el-pagination
                        @current-change="handleCurrentChange"
                        :current-page.sync="paging.page"
                        :page-size="paging.limit"
                        layout="prev, pager, next, jumper"
                        :total="paging.total">
                    </el-pagination>
                </div>
            </div>
       </div>
       <router-view></router-view>
    </div>
</template>

<script>
export default {
    data() {
        return {
            statistics:true,
            paging:{
                store:'',//门店ID
                submit_time:'',//提交时间
                name:'',//	姓名
                type:'',//请假类型
                page:1,
                total:0,
                limit:10,
            },
            today:'',
            loading:false,
            shopList:[],
            dayList:[],
            monthList:[],
            positionList:[],
            classesList:[],
            leaveTypeList:[],
            tableData: [],
            isDerive:false,
            isDerive2:false
        };
    },
    created() {
        let date = new Date();
        this.today = `${date.getFullYear()}-${date.getMonth()+1}`
        this.paging.date = this.today;
        this.homegetStore();

        // this.homegetPosition();
        // this.staffshiftType();
        // this.getleaveType();
        this.getList();
    },
    filters:{
    },
    methods: {
        async leaveDel(row){
            this.$msgbox({
                title: '提示',
                message: '确定要删除该请假记录吗?',
                type: 'warning',
                showCancelButton: true,
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                beforeClose:async (action, instance, done) => {
                    if (action === 'confirm') {
                    instance.confirmButtonLoading = true;
                    instance.confirmButtonText = '执行中...';
                    let {code,data} = await this.$Http.leaveDel({ids:row.id+''})
                        if(code){
                            this.$message.success('删除成功!');
                            this.handleCurrentChange(1)
                        }
                        done();
                        instance.confirmButtonLoading = false;
                    } else {
                        done();
                    }
                }
            }).then(action => {

            }).catch(()=>{});
        },
        async leaveImport(e){
            let file = e.target.files[0];
            if (!file) return;
            this.isDerive = true;
            this.$refs.uploadPai.value = "";
            let { code, data } = await this.$Http.leaveImport({ files: file }, true);
            this.isDerive = false;
            if (code) {
                this.$message.success('导入成功!')
                this.init(1);
            }
        },
        statChange(e){//

        },
        init(val){
            this.paging = this.$options.data().paging;
            this.paging.date = this.today;
            this.classesList = [];
            this.handleCurrentChange(1)
        },
        //获取班次类型
        async getleaveType(){
            let {code,data} = await this.$Http.getleaveType();
            if(code){
                this.leaveTypeList = data;
            }
        },
        //获取班次
        async staffshiftType(){
            if(!this.paging.store_id)return;
            let {code,data} = await this.$Http.staffshiftType({
                store_id:this.paging.store_id,
            });
            if(code){
                this.classesList = data;
            }
        },
        // 获取岗位
        async homegetPosition() {
            let { code, data } = await this.$Http.homegetPosition();
            if (code) {
                this.positionList = data;
            }
        },
        async attendanceStatistics(){
            
        },
        async attendanceStatisticsMonth(){
            this.loading = true;
            let {code,data} = await this.$Http.attendanceStatisticsMonth(this.paging);
            this.loading = false;
            if(code){
                this.monthList = data.data;
                this.paging.total = data.total;
            }
        },
        async homegetStore(){
            let {code,data} = await this.$Http.homegetStore();
            if(code){
                this.shopList = data;
            }
        },
        handleCurrentChange(val){
            this.paging.page = val;
            this.getList()
        },
        async getList(){
            this.loading = true;
            let obj = {...this.paging};
            var {code,data} = await this.$Http.leaveList(obj);
            this.loading = false;
            if(code){
                this.monthList = data.data;
                this.paging.total = data.total;
            }
        },
        pickerDate(){

        },
        change(){

        }
    },
};
</script>

<style lang="scss" scoped>
::v-deep{
    .el-table{
        overflow: inherit;
    }
    .el-table__header-wrapper{
        position: sticky;
        top: 0;
        width: 100%;
        z-index: 99;
    }
    // .el-table__body-wrapper{
    //     height: 80vh;
    //     overflow: auto;
    // }
}
.statistics{
    padding-bottom:20px;
    display: flex;
    justify-content: center;
}
.image-thumbnail{
    width: 130px;
    height: 130px;
}
.btn-upload {
  position: relative;
  overflow: hidden;
  input[type="file"] {
    width: 100%;
    cursor: pointer;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    opacity: 0;
  }
  input[type="file"]::-webkit-file-upload-button {
    cursor: pointer;
  }
}
</style>